<!-- 
此组件初始化时不会自动加载数据，请在mounted中 this.$refs.[].initData()
如果放在dialog里面的吗，请在dialog的open事件中用this.$nextTick进行加载
 -->
<template>
  <div>
    <list id-key="id" ref="list" unit="工作流" :disabled="disabled" :show-query="showQuery" show-checkbox
      :query-params="queryParams" expand-query  page @get-data="onGetData" :data="data" custom-get-data>
      <template #toolbar-left>
        <slot name="toolbar-left"></slot>
      </template>
      <template #query>
        <!-- <el-form-item label="ID">
          <el-input v-model.trim="queryParams.id" clearable></el-input>
        </el-form-item> -->
        <div>
          <el-form-item label="编号">
            <el-input v-model.trim="queryParams.no" placeholder="工作流编号" clearable></el-input>
          </el-form-item>
          <el-form-item label="工作名">
            <el-input v-model.trim="queryParams.name" placeholder="工作名称" clearable></el-input>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="queryParams.statuses" clearable multiple collapse-tags>
              <el-option label="草稿" :value="0"></el-option>
              <el-option label="待处理" :value="1"></el-option>
              <el-option label="处理中" :value="2"></el-option>
              <el-option label="驳回" :value="3"></el-option>
              <el-option label="办结" :value="4"></el-option>
              <el-option label="撤回" :value="5"></el-option>
              <el-option label="作废" :value="6"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="流程">
            <el-select v-model="queryParams.workflowCodes" clearable multiple collapse-tags>
              <el-option label="草稿" :value="0"></el-option>
              <el-option label="待处理" :value="1"></el-option>
              <el-option label="处理中" :value="2"></el-option>
              <el-option label="驳回" :value="3"></el-option>
              <el-option label="办结" :value="4"></el-option>
              <el-option label="撤回" :value="5"></el-option>
              <el-option label="作废" :value="6"></el-option>
            </el-select>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="工作流ID">
            <el-input v-model="queryParams.idString" placeholder="工作流ID，以,分隔" clearable
              style="width:800px;max-width:none"></el-input>
          </el-form-item>
        </div>
      </template>
      <template #column>
        <el-table-column prop="no" width="160" label="编号">
          <template #default="{ row }">
            <span class="c-link" @click="openDetail(row.id)">{{ row.no }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" min-width="180" label="工作名" show-overflow-tooltip>
          <template #default="{ row }">
            <el-tag v-if="row.isDeleted" type="danger" style="margin-right:5px">已删</el-tag>
            {{ row.name }}
          </template>
        </el-table-column>
        <el-table-column prop="statusName" width="80" align="center" label="状态">
          <template #default="{ row }">
            <el-tag :type="getStatusType(row.status)">{{ row.statusName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="applicationUserName" width="90" label="申请人" align="center">
          <template #default="{ row }">
            <span class="c-link" @click="openUserDetail(row.applicationUserId)">{{ row.applicationUserName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="applicationTime" width="120" label="申请时间" sortable="custom">
          <template v-slot="{ row }">
            <span>{{ row.applicationTime | toShortDatetimeString }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="workflowName" width="140" label="流程名称" show-overflow-tooltip />



        <el-table-column prop="creationTime" width="120" label="创建时间" sortable="custom">
          <template v-slot="{ row }">
            <span>{{ row.creationTime | toShortDatetimeString }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="lastModificationTime" width="120" label="更新时间" sortable="custom">
          <template v-slot="{ row }">
            <span>{{ row.lastModificationTime | toShortDatetimeString }}</span>
          </template>
        </el-table-column>
        <!-- slot[column] -->
        <slot name="column"></slot>
        <!--/ slot[column]-->
      </template>
    </list>
    <detail-dialog ref="detailDialog" :in-dialog="inDialog" />
  </div>
</template>
<script>
import listMixin from "@/mixins/list";
import list from "@/components/common/list";
import detailDialog from "@/components/wf/workflow/detailDialog";
import api from "@/api/wf/workflow";
export default {
  mixins: [listMixin],
  components: {
    list,
    detailDialog,
  },
  props: {},
  data() {
    return {
      //查询条件字段
      queryParams: {
        name: "",
        enName: "",
        zhName: "",
        address: "",
        statuses: []
      },
      data: [],
      total: 0
    };
  },
  methods: {
    async showMenuPermissionDialog(roleId) {
      await this.$refs.permissionMenusDialog.showByRoleId(roleId);
    },
    async onGetData(params) {
      this.$refs.list.loading(true);
      let res = await api.getPageList(params);
      this.data = res.data.list;
      this.total = res.data.total;
      this.$refs.list.loading(false);
    },
    reload() {
      this.$refs.list.reload();
    },
    getStatusType(status) {
      var text = "";
      switch (status) {
        case 0:
          text = "info";
          break;
        case 1:
          text = "";
          break;
        case 2:
          //处理中
          text = "primary";
          break;
        case 3:
          //驳回
          text = "danger";
          break;
        case 4:
          //办结
          text = "success";
          break;
        case 5:
          text = "warning";
          break;
        case 6:
          text = "info";
          break;
      }
      return text;
    },
    openDetail(id) {
      this.$refs.detailDialog.openDetail(id);
    },
    openUserDetail(userId) {

    }
  },
};
</script>